package com.mindskip.xzs.controller.admin;

import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.base.BaseApiController;
import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.domain.User;
import com.mindskip.xzs.service.DepartmentUserService;
import com.mindskip.xzs.viewmodel.admin.dept.AddSidelineReq;
import com.mindskip.xzs.viewmodel.admin.dept.SidelineRes;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author artka
 * @description:
 * @date 2022/9/16 10:58 PM
 */
@RestController("DeptUserController")
@RequestMapping(value = "/api/admin/deptUser")
public class DeptUserController extends BaseApiController {

    @Resource
    private DepartmentUserService departmentUserService;

    /**
     * 查询兼职列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public RestResponse<PageInfo<SidelineRes>> selectCategory(@RequestParam(required = false, value = "userId") Integer userId,
                                                              @RequestParam(required = false, value = "deptId") Long deptId,
                                                              @RequestParam(required = false, value = "pageNum", defaultValue = "1") Integer pageNum,
                                                              @RequestParam(required = false, value = "pageSize", defaultValue = "10") Integer pageSize) {
        return RestResponse.ok(departmentUserService.pageSideline(userId, deptId, pageNum, pageSize));
    }

    @PostMapping("/add")
    public RestResponse<Boolean> addExam(@RequestBody @Valid AddSidelineReq req) {
        return RestResponse.ok(departmentUserService.addSideline(req));
    }

    @PostMapping("/del")
    public RestResponse<Boolean> addExam(@RequestParam Integer id) {
        return RestResponse.ok(departmentUserService.delSideline(id,getCurrentUser()));
    }
}
